
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/commonly-used-show.css" />
    <script type="text/javascript" src="weddingPhotography/js/jquery.min.js"></script>
    <script type="text/javascript" src="weddingPhotography/js/bootstrap.js" ></script>

     <title>修改密码</title>


</head>

<body class="mybody">



<c:if test="${user_leve == 0}">
    <jsp:include page="theTopMenuAdmin.jsp" />
</c:if>

<c:if test="${user_leve == 2}">
    <jsp:include page="theTopMenuUser.jsp" />
</c:if>


<div class="container">
    <div class="frame">
        <h3 style="text-align: center">修改用户密码</h3>
        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3"/>

        <div id="personal_user" style="margin-left: 40%; margin-right: 40%">

            <div class="form-group">
                <label for="user_loing_passwd"><b style="color: red">*&nbsp</b>原登录密码：</label>
                <input type="text" id="user_loing_passwd" class="form-control edit" placeholder="请输入原登录密码" v-model="user_loing_passwd">
            </div>

            <div class="form-group">
                <label for="new_user_loing_passwd"><b style="color: red">*&nbsp</b>新密码：</label>
                <input type="text" id="new_user_loing_passwd" class="form-control edit" placeholder="请输入新密码" v-model="new_user_loing_passwd">
            </div>

            <div class="form-group">
                <label for="ok_user_loing_passwd"><b style="color: red">*&nbsp</b>确认密码：</label>
                <input type="text" id="ok_user_loing_passwd" class="form-control edit" placeholder="请输入确认密码" v-model="ok_user_loing_passwd">
            </div>
        </div>

        <div class="text-center">
            <div class="form-group">
                <input type="button" value="修改" class="btn btn-primary" onclick="updta_passwd()">
                <input type="reset" value="重置" class="btn btn-danger interval" onclick="reset()">
            </div>

            <div>
                <label id="user_null" style="color: red"></label>
            </div>
        </div>

    </div>
</div>


<script type="text/javascript">

    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    function reset(){
        var addUser = document.getElementById("personal_user");
        var ipts = addUser.getElementsByTagName("input");
        for (var i = 0; i < ipts.length; i++){
            ipts[i].value = "";
        }
    }


    function updta_passwd(){
        var userLoingPasswd = $("#user_loing_passwd").val();
        var newuserLoingPasswd = $("#new_user_loing_passwd").val();
        var okuserLoingPasswd = $("#ok_user_loing_passwd").val();
        var userNull = document.getElementById("user_null");

        if ($.isEmptyObject(userLoingPasswd)){
            userNull.innerHTML = "原密码不能为空";
            return false;
        }else if ($.isEmptyObject(newuserLoingPasswd)){
            userNull.innerHTML = "新密码不能为空";
            return false;
        }else if ($.isEmptyObject(okuserLoingPasswd)){
            userNull.innerHTML = "确认密码不能为空";
            return false;
        }else {
            userNull.innerHTML = "";
        }

        if(newuserLoingPasswd !== okuserLoingPasswd){
            userNull.innerHTML = "新密码与确认密码不一致";
            return false;
        }else {
            userNull.innerHTML = "";
        }


        var postUrl = "${pageContext.request.contextPath}/member/userPassword";
        var str = {
            "id": userdt.result.id,
            "userLoginPwd": okuserLoingPasswd
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    userNull.innerHTML = data.msg;
                }else {
                    location.href = "${pageContext.request.contextPath}/login";
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>